<?php

class app_install extends app
{

	public function __construct()
	{
	    parent::__contruct( 'install', '安装系统' );
	    
		$task = request('task');
		if($task!='complete')
		{
			$db = bone::get_db();
			if( !$db->get_error() )
			{
				$tables = $db->get_tables();
				print_r($tables);
				if( in_array($tables, 'bone_user') ) $this->redirect('./?app=install&task=complete');
			}
		}
	}


	public function setting()	// 配置数据库
	{
		$template = $this->get_template('setting');
		$template->set_title('配置数据库');
		$template->display();
	}


	public function setting_save()	// 保存配置
	{
		$config_db = bone::get_config('db');
		$config_db->db_host = post('db_host', '');
		$config_db->db_user = post('db_user', '');
		$config_db->db_pass = post('db_pass', '');
		$config_db->db_name = post('db_name', '');

		$model_install = $this->get_model();
		$model_install->save_config($config_db, BONE_ROOT.DS.'configs'.DS.'db.php');

		$db = bone::get_db();
		
        $error = $db->get_error();
		if( $error!=nulll )
		{
			$this->redirect('./?app=install&task=setting', $error, 'error');
		}
		else
		{
			$model_install->install();
			$this->redirect('./?app=install&task=complete');
		}
	}


	public function complete()
	{
		$template = $this->get_template('complete');
		$template->set_title('完成配置');
		$template->display();
		
		/*
		$path = BONE_ROOT.DS.'setup.html';
		if( file_exists( $path ) ) @unlink( $path );

		$path = BONE_ROOT.DS.'apps'.DS.'install';
		if( file_exists( $path ) )
		{
			$fso = bone::get_lib('fso');
			$fso->rm_dir( $path );
		}
		*/

	}




}
?>